package cn.edu.ctbu.test.controller;


import cn.edu.ctbu.test.domain.Course;
import cn.edu.ctbu.test.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CourseController {
    @Autowired
    CourseService courseService;

    @RequestMapping("/course/course")
    public String List(HttpServletRequest httprequest, Model model)
    {
        HttpSession session=httprequest.getSession();

        if(session.getAttribute("userid")==null){
            //未登录，需要登录
            return "redirect:index";
        }


        List<Course> courses=courseService.findAll();

        model.addAttribute("data",courses);

        return "course/course";
    }
}
